package com.yf.stat.modules.total.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.yf.base.utils.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
* <p>
* 学习统计数据传输类
* </p>
*
* @author 聪明笨狗
* @since 2021-06-04 10:13
*/
@Data
@ApiModel(value="学习统计", description="学习统计")
public class StatTotalLearnDTO implements Serializable {

    private static final long serialVersionUID = 1L;


    @ApiModelProperty(value = "ID", required=true)
    private String id;

    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @ApiModelProperty(value = "统计时间")
    private Date statDate;

    @ApiModelProperty(value = "课程ID")
    private String courseId;

    @ApiModelProperty(value = "学习用户数")
    private Integer learnUser;

    @ApiModelProperty(value = "学完用户数")
    private Integer finishUser;

    @ApiModelProperty(value = "人均时长")
    private Long learnSec;

    /**
     * 月份格式化
     * @return
     */
    public String getDateStr(){
        return DateUtils.formatDate(statDate, "MM/dd");
    }

    /**
     * 平均学习时间
     * @return
     */
    public Long getAvgTime(){
        if(learnSec>0 && learnUser>0){
            return learnSec / learnUser;
        }
        return 0L;
    }

}
